﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.DataHub
{
    /// <summary>
    /// 临床诊断
    /// </summary>
    public class ClncDiagDictService : CrudAppService<ClncDiagDict, ClncDiagDictDto, Guid, ClncDiagDictInput, ClncDiagDictCreateDto, ClncDiagDictUpdateDto>, IClncDiagDictService
    {
        private IRepository<ClncDiagDict, Guid> _clncDiagDictRepository;

        public ClncDiagDictService(IRepository<ClncDiagDict, Guid> ClncDiagDictRepository) : base(ClncDiagDictRepository)
        {
            _clncDiagDictRepository = ClncDiagDictRepository;
        }

        /// <summary>
        /// 获取临床诊断字典列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<ClncDiagDictDto>> GetListAsync(ClncDiagDictInput input)
        {
            var iQuery = await _clncDiagDictRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<ClncDiagDict>, List<ClncDiagDictDto>>(iQuery.ToList());

                return new PagedResultDto<ClncDiagDictDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<ClncDiagDict>, List<ClncDiagDictDto>>(items.ToList());

                return new PagedResultDto<ClncDiagDictDto>(totalCount, itemsDto);
            }
        }
    }
}
